package com.up.blog.controller;

import com.alibaba.fastjson.JSON;
import com.up.blog.domain.Articlebean;
import com.up.blog.domain.Pagebean;
import com.up.blog.service.GetArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;
@Controller
public class ArticleController  {
    @Autowired
    private GetArticlesService getArticles;
    public static Integer page;
    public static Integer limit;

    @RequestMapping(value = "/getarticle", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String findUserById(HttpServletRequest req, HttpServletResponse resp) {
        page = Integer.valueOf(req.getParameter("page"));
        limit = Integer.valueOf(req.getParameter("limit"));
        Pagebean pagebean=new Pagebean();
        String ret=null;
        try {
            List<Articlebean> articlebeanList=getArticles.getArticlebean();
            Long i=getArticles.getCount();
            pagebean.setData(articlebeanList);
            pagebean.setCount(i);
            if(i>0){
                pagebean.setCode(0);
            }else
                pagebean.setCode(1);
                ret=JSON.toJSONString(pagebean);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ret;
    }
}
